/*
 * @Author: sanshichen
 * @Date: 2018-04-06 11:30:27
 * @Last Modified by:   sanshichen
 * @Last Modified time: 2018-04-06 11:30:27
 * @Description: 获取目录
*/
'use strict';
const fs = require('fs');
const path = require('path');
const { readDir } = require('../extend/helper');

// 读取目录中的markdown文档
module.exports = source => {
  return async () => {
    return await readDir(source).then(data => {
      return data.filter(res => {
        const file_path = `${source}/${res}`;
        const stats = fs.statSync(file_path);
        const extname = path.extname(file_path);
        if (stats.isFile() && extname === '.md') {
          return true;
        }
        return false;
      }).map(res => {
        return path.basename(res, '.md');
      });
    });
  };
};

